<template>
  <div class="publicBox" id="updataCss">

<el-form ref="form" :inline="true"  class="demo-form-inline">
<div>
    <span class="tipsText">*此更新管理只针对Android端</span>
</div>

 <el-form-item class="btn_box">
            <el-button class="pubBtnGree140" @click="Newupdata()" type="primary">新建版本</el-button>
  </el-form-item>
</el-form>

<div class="banbentext">
    <span>当前版本</span>
</div>

<!-- <el-row> -->
<div>

   <public-table  
          @handleEdit="handleEdit" 
          :columnDefs="columnDefs" 
          :tableData="tableData" 
          :order=false
          @handleDownload="handleDownload"
          @handleUpdata="handleUpdata"
          :btn="['download']"></public-table>
</div>


<div style="margin-top:12px"></div>

<div class="banbentext">
    <span>历史版本</span>
</div>


  <div>
     <public-table  
          @handleEdit="handleEdit"
          @changePage="changePage"
          :columnDefs="columnDefs" 
          :tableData="tableDataA" 
          @handleDownload="handleDownload"
          :order=false
          :total="total"
          @handleUpdata="handleUpdata"
          :btn="['edit','download','updata']">
          </public-table>
  </div>


</div>
</template>

<script>
import publicTable from "@/components/public/publicTable.vue"
import * as API from "@api/banner.js"
import Vue from 'vue'
export default {
  components: {
 publicTable
  },
  data() {
      return{
        pageNum:1,
        pageSize:100,
        total:0,
           columnDefs :[
            {headerName: '发布时间', field: 'createtime',width:287},
            {headerName: '版本号', field: 'version',width:287},
            {headerName: '升级类型', field: 'upgradetype',width:287},
            {headerName: '升级提示', field: 'description',width:287},
        ],
          tableData:[],
          tableDataA:[],
          listArr:[],
          id:'',
      }
  },
  // 计算属性，会监听依赖属性值随之变化
  computed: {
  },
  // 监控data中的数据变化
  watch: {
  
  },
  // filters:{
  //     Changetransf(value){
  //         if(value == 0){
  //           value = "非强制升级"
  //         }else{
  //           value = "强制升级"
  //         }
  //     }
  // },
  methods: {
    changePage(pageSize,pageNum){
          this.pageSize=pageSize;this.pageNum=pageNum
          this.init()
    },
    async init(){
      let params={page:this.pageNum,size:this.pageSize}
      await API.getUpdata(params).then(res=>{
        if(res.IsPositive){
          this.tableDataA = res.Data
        }
      })
    },

    async initA(){
      let that=this
      await API.getUpdataOne().then(res=>{
        if(res.IsPositive){
          that.tableData = {
            records:[res.Data]
          }
        }
      })
    },

    handleEdit(row){
      this.$router.push({path:"/platform/banner/upNewbuild",query:{data:row}})
    },
    handleDownload(row,index){
        window.location.href = row.url
    },
    handleUpdata(row,index){
      this.id = row.idstr
      API.changeUpdata(this.id).then(res=>{
        if(res.IsPositive){
            this.init()
        }
      })
      
    },
    Newupdata(){
       this.$router.push({path:"/platform/banner/upNewbuild"})
    }

  },
    filters:{
      ChangeDateFormat(value){
          if(value && value!="") return Vue.prototype.ChangeDateFormat(value,true)
          return ""
      }
  },
  created() {
    this.initA()
    this.init()
    
  },
  mounted() {


  },
  beforeCreate() {}, // 生命周期 - 创建之前
  beforeMount() {}, // 生命周期 - 挂载之前
  beforeUpdate() {}, // 生命周期 - 更新之前
  updated() {}, // 生命周期 - 更新之后
  beforeDestroy() {}, // 生命周期 - 销毁之前
  destroyed() {}, // 生命周期 - 销毁完成
  activated() {}, // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>

<style lang='less' scoped>
@import "../../styles/less/public.less";
#updataCss{
  .tipsText{
      color:#F40404;
  }
  .btn_box{
      margin-top: 11px;
  }
  .banbentext{
      display: flex;
      flex-direction: row;
      justify-content: flex-start;
      margin-bottom: 10px;
  }
}


</style>